local skel = fk.CreateSkill {
  name = "emo__kuiguang",
}

skel:addEffect("active", {
  anim_type = "offensive",
  prompt = "#emo__kuiguang",
  card_num = 1,
  min_target_num = 1,
  card_filter = function(self, player, to_select, selected)
    return #selected == 0 and Fk:getCardById(to_select).name == "peach"
  end,
  target_filter = function (self, player, to, selected, selected_cards)
    if #selected_cards == 0 then return false end
    local slash = Fk:cloneCard("slash")
    slash.skillName = skel.name
    slash:addSubcard(selected_cards[1])
    if player:isProhibited(to, slash) then return false end
    local last, next = player:getLastAlive(), player:getNextAlive()
    if #selected == 0 then return to == next or to == last end
    if selected[1] == last then
      local temp = to:getNextAlive()
      for _ = 1, 10 do
        if temp == player then return true end
        if not table.contains(selected, temp) then return false end
        temp = temp:getNextAlive()
      end
    elseif selected[1] == next then
      local temp = to:getLastAlive()
      for _ = 1, 10 do
        if temp == player then return true end
        if not table.contains(selected, temp) then return false end
        temp = temp:getLastAlive()
      end
    end
  end,
  can_use = function (self, player)
    return true
  end,
  on_use = function (self, room, effect)
    local player = effect.from
    local slash = Fk:cloneCard("slash")
    slash.skillName = skel.name
    slash:addSubcards(effect.cards)
    local use = { ---@type UseCardDataSpec
      from = player,
      tos = effect.tos,
      card = slash,
      extraUse = true,
    }
    if effect.tos[1] == player:getLastAlive() then
      use.extra_data = {emo__kuiguang_reverse = true}
    end
    room:useCard(use)
  end,
})

-- 小巧思，顺时针选目标会改为顺时针结算
skel:addEffect(fk.BeforeCardUseEffect, {
  is_delay_effect = true,
  can_trigger = function(self, event, target, player, data)
    return target == player and (data.extra_data or Util.DummyTable).emo__kuiguang_reverse
  end,
  on_use = function(self, event, target, player, data)
    data.tos = table.reverse(data.tos)
  end,
})

Fk:loadTranslationTable{
  ["emo__kuiguang"] = "溃光",
  [":emo__kuiguang"] = "出牌阶段，你可以将【桃】当【杀】沿顺时针或逆时针对连续的任意名角色使用。",
  ["#emo__kuiguang"] = "将【桃】当【杀】使用",
}

return skel
